<?php

namespace App\Models;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;

class Collections extends Common
{
    protected $guarded = [];

    /**
     * 类别表
     */
    protected $table = 'rap_collections';
    public      $timestamps = false;

    /**
     * 允许批量赋值的字段
     * */
    protected $fillable = [];

    /**
     * 隐藏字段
     * */
    protected $hidden = [];

    public function user() {
        return $this->belongsTo('App\Models\Wxusers','user_id');
    }

    public function music() {
        return $this->belongsTo('App\Models\MusicCreation','object_id');
    }

    public function beat() {
        return $this->belongsTo('App\Models\Beat','object_id');
    }
    /**
     * @param array $where
     * @return array
     * @name 根据条件获取一条数据
     * @user IHammer
     */
    public static function getInfo($where=array()){
        $res = self::where($where)->first();
        if($res){
            return $res->toArray();
        }
        return [];
    }

    /**
     * @param $request
     * @return array
     * @name 列表
     * @user IHammer
     */
    public static function getListsWx($request){
        $pageSize = $request->get('pageSize')?:10;
        $user_id = $request->get("user_id")?:0;
        $where = array();
        if(!empty($user_id)){
            $where[] = ['user_id','=',$user_id];
        }
        $res = self::where($where)
            ->orderBy('id','desc')
            ->paginate($pageSize);
        if($res){
            return $res->toArray();
        }
        return [];
    }

}
